package com.member.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.member.common.utils.DateUtils;
import com.member.shop.domain.SysBizRaffleResults;
import com.member.shop.mapper.SysBizRaffleResultsMapper;
import com.member.shop.service.ISysBizRaffleResultsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 抽奖结果Service业务层处理
 *
 * @author thomas
 * @date 2024-03-21
 */
@Service
public class SysBizRaffleResultsServiceImpl extends ServiceImpl<SysBizRaffleResultsMapper, SysBizRaffleResults> implements ISysBizRaffleResultsService {
    @Resource
    private SysBizRaffleResultsMapper sysBizRaffleResultsMapper;

    /**
     * 查询抽奖结果
     *
     * @param resultId 抽奖结果主键
     * @return 抽奖结果
     */
    @Override
    public SysBizRaffleResults selectSysBizRaffleResultsByResultId(Long resultId) {
        return sysBizRaffleResultsMapper.selectById(resultId);
    }

    /**
     * 查询抽奖结果列表
     *
     * @param queryWrapper 抽奖结果
     * @return 抽奖结果
     */
    @Override
    public List<SysBizRaffleResults> selectSysBizRaffleResultsList(SysBizRaffleResults queryWrapper) {
        return sysBizRaffleResultsMapper.selectSysBizRaffleResultsList(queryWrapper);
    }

    /**
     * 新增抽奖结果
     *
     * @param sysBizRaffleResults 抽奖结果
     * @return 结果
     */
    @Override
    public int insertSysBizRaffleResults(SysBizRaffleResults sysBizRaffleResults) {
        sysBizRaffleResults.setCreateTime(DateUtils.getNowDate());
        return sysBizRaffleResultsMapper.insert(sysBizRaffleResults);
    }

    /**
     * 修改抽奖结果
     *
     * @param sysBizRaffleResults 抽奖结果
     * @return 结果
     */
    @Override
    public int updateSysBizRaffleResults(SysBizRaffleResults sysBizRaffleResults) {
        sysBizRaffleResults.setUpdateTime(DateUtils.getNowDate());
        return sysBizRaffleResultsMapper.updateById(sysBizRaffleResults);
    }

    /**
     * 批量删除抽奖结果
     *
     * @param resultIds 需要删除的抽奖结果主键
     * @return 结果
     */
    @Override
    public int deleteSysBizRaffleResultsByResultIds(Long[] resultIds) {
        return sysBizRaffleResultsMapper.deleteBatchIds(Arrays.asList(resultIds));
    }

    /**
     * 删除抽奖结果信息
     *
     * @param resultId 抽奖结果主键
     * @return 结果
     */
    @Override
    public int deleteSysBizRaffleResultsByResultId(Long resultId) {
        return sysBizRaffleResultsMapper.deleteById(resultId);
    }

    @Override
    public List<SysBizRaffleResults> selectByActivitId(Long activityId, Long uid) {
        return sysBizRaffleResultsMapper.selectByActivitId(activityId, uid);
    }

    @Override
    public void updateExtractStatus(Long id, Integer extractStatus) {
        LambdaUpdateWrapper<SysBizRaffleResults> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(SysBizRaffleResults::getResultId, id);
        updateWrapper.set(SysBizRaffleResults::getUpdateTime, new Date());
        updateWrapper.set(SysBizRaffleResults::getExtractStatus, extractStatus);
        this.update(updateWrapper);
    }
}
